<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/12/24 0024
  Time: 14:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>工序物料设计单审核页面</title>
    <link rel="stylesheet"  href="/bootstrap/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/manufactureCss/b/Process_material_design_sheet_review.css" />
    <style type="text/css">

    </style>
</head>
<body style="padding: 15px 50px;background-color: #eeeeee;">
<div class="panel-heading hhead">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <span style="color: blue;">您正在做的业务是：</span>
            <li class="breadcrumb-item"><a href="#">生产管理</a></li>
            <li class="breadcrumb-item"><a href="#">工序物料设计</a></li>
            <li class="breadcrumb-item active" aria-current="page">工序物料设计单审核</li>
        </ol>
    </nav>
</div>
<form id="fm">
<div style="margin-bottom: 2px">
    <div style="display: inline;margin-left: 75%;">
        <input type="hidden" id="register" name="register" value="">
        <input type="radio" name="checkTag" value="3"/>未通过
        <input type="radio" name="checkTag" value="2"/>通过
        <button class="btn btn-primary" type="button" id="ok">确认</button>
<%--        <button class="btn btn-primary">返回</button>--%>
    </div>
</div> <!-- 此div改用栅格来做 -->
</form>
<input type="hidden" id="userName" name="userName" value="${user.loginId}">
<div id="designListBox" style="height: 480px">
    <div style="text-align: center">
        <h3>工序物料设计单</h3>
    </div>
    <div style="padding: 30px">
        <table class="tbl1">
            <tr>
                <td class="col1">工序单编号：</td>
                <td class="col2" id="designId">aaa</td>
                <td class="col1">设计人：</td>
                <td class="col2" id="designer"></td>
            </tr>
            <tr>
                <td class="col1">产品名称：</td>
                <td colspan="1" id="productName">
                    小米笔记本
                </td>
                <td class="col1">产品编号：</td>
                <td colspan="2" id="productId">
                    aaaaaaaaaaaaaaa
                </td>
            </tr>
        </table>

        <table id="tbl2" class="table table-bordered" style="margin: 15px auto;">
            <thead>
            <tr>
                <th>序号</th><th width="85px">工序名称</th><th width="85px">工序编号</th>
                <th width="380px">描述</th><th width="110px">工时数(小时)</th><th width="150px">工时成本小计(元)</th>
                <th width="120px">物料成本小计</th><th>详情</th>
            </tr>
            </thead>
            <tbody id="template">

            </tbody>
        </table>

        <table class="tbl1">
            <tr>
                <td class="col1">工时总成本：</td>
                <td class="col2" id="costPriceSum">30.00</td>
                <td class="col1">物料总成本：</td>
                <td class="col2" id="moduleCostPriceSum">2500.00</td>
            </tr>
            <tr>
                <td class="col1">设计要求：</td>
                <td colspan="3" style="padding-top: 5px" id="procedureDescribe">
                    aaaaaaaaaaaaaaaaaaaaa
                </td>
            </tr>
            <tr>
                <td class="col1">审核人：</td>
                <td class="col2"><input type="text" class="txt_under_line" id="register2"></td>
                <td class="col1">审核时间：</td> <td class="col2" id="time"></td>
            </tr>
            <tr>
                <td class="col1">审核意见：</td>
                <td colspan="3" style="padding-top: 5px">
                    <textarea rows="2" cols="100" id="checkSuggestion"></textarea>
                </td>
            </tr>

        </table>
    </div>
</div>
<div class="modal fade" id="AddProductProcessMaterialModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl">
        <div class="modal-content" style="height: 450px">
            <div class="modal-header" style="height: 8%">
                <h3 class="modal-title" id="staticBackdropLabel">添加物料</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" style="height: 100%;width: 100%;margin: -1%">
                <iframe id="iframe2" src="" style="width: 100%;height: 99%"></iframe>
            </div>
            <div class="modal-footer" style="height: 15%">
                <button id="btnConcel" class="btn btn-success" data-bs-dismiss="modal">
                    确认<span class="glyphicon glyphicon-remove"></span>
                </button>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="/js/jquery-3.7.0.min.js"></script>
<script type="text/javascript" src="/bootstrap/bootstrap-5.3.3-dist/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript" src="/js/common.js"></script>
<script type="text/javascript">
    $(function () {
        // 初始化时间
        setInterval(updateDateTime, 1000);

        initialDesignSheet();

        $("#ok").click(function () {
            let checkTag = $("input[name='checkTag']:checked").val();
            let Register = $("input[id='register2']").val();
            let checkSuggestion = $("#checkSuggestion").val();
            let id = sessionStorage.getItem("id");
            if(checkTag === undefined){
                alert("请选择审核结果");
                return;
            }
            if(checkSuggestion === ""){
                alert("请输入审核意见");
                return;
            }
            if(Register === ""){
                let userName = $("#userName").val();
                $("input[name='register']").val(userName);
                $("input[id='register2']").val(userName);
            }else {
                $("input[name='register']").val(Register);
            }
            let register = $("input[name='register']").val();
            let data = {
                id:id,
                checkTag:checkTag,
                register:register,
                checkSuggestion:checkSuggestion
            }
            sessionStorage.setItem("data",JSON.stringify(data));
            alert("已提交！")
        })

    })
    function initialDesignSheet(){
        let id = sessionStorage.getItem("id");
        $.ajax({
            type: "GET",
            url: "/m-design-procedure-module/initialDesignSheet?id="+id,
            dataType: "json",
            success: function (data){
                console.log(data);
                $("#designId").text(data.designId);
                $("#designer").text(data.designer);
                $("#procedureDescribe").text(data.procedureDescribe);
                $("#productId").text(data.productId);
                $("#productName").text(data.productName);
                $("#costPriceSum").text(data.costPriceSum);
                $("#moduleCostPriceSum").text(data.moduleCostPriceSum);
                // $("#id").val(data.id);
                initialTable(id);
            }
        })
    }
    function initialTable(id){
        $.ajax({
            type: "GET",
            url: "/m-design-procedure-details/selectArrByParentId?id="+id,
            dataType: "json",
            success: function (data){
                console.log(data);
                $("#template").empty()

                for (let i = 0; i < data.length; i++) {
                    let moduleSubtotal = 0;
                    data[i].moduleSubtotal === null ? moduleSubtotal = 0 : moduleSubtotal = data[i].moduleSubtotal;
                    let tr = "<tr>" +
                        "<td class='ckbox' id='"+data[i].procedureId+"'>"+(i+1)+"</td>" +
                        "<td>"+data[i].procedureName+"</td>" +
                        "<td>"+data[i].procedureId+"</td>" +
                        "<td>"+data[i].procedureDescribe+"</td>" +
                        "<td class='num'>"+data[i].labourHourAmount+"</td>" +
                        "<td class='num'>"+data[i].subtotal+"</td>" +
                        "<td class='num'>"+moduleSubtotal+"</td>" +
                        '<td><a href="javascript:select('+'\''+data[i].id+'\''+','+'\''+data[i].procedureName+'\''+','+'\''+data[i].register+'\''+','+'\''+data[i].registerTime+'\''+')" class="btn btn-outline-success">查看</a></td>' +
                        "</tr>";
                    $("#template").append(tr);
                }
            }
        })
    }
    function select(procedureId,procedureName,register,registerTime) {
        sessionStorage.setItem("procedureName",procedureName);
        sessionStorage.setItem("register",register);
        sessionStorage.setItem("registerTime",registerTime);
        sessionStorage.setItem("designId",$("#designId").text())
        sessionStorage.setItem("procedureId",procedureId);
        $("#AddProductProcessMaterialModal").modal("show");
        $("#iframe2").attr("src","/m-design-procedure-module/ProcessMaterialDesignSheetReviewSub");
    }
    function updateDateTime(){
        let date = new Date();
        let year = date.getFullYear();
        let month = (date.getMonth() + 1).toString().padStart(2, '0');
        let day = date.getDate().toString().padStart(2,'0');
        let hours = date.getHours().toString().padStart(2,'0');
        let minutes = date.getMinutes().toString().padStart(2,'0');
        let seconds = date.getSeconds().toString().padStart(2,'0');
        let dateTimeStr = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
        $("#time").text(dateTimeStr);
    }
</script>
</body>
</html>
